package com.zhihuitong.meeting.login;

import com.zhihuitong.meeting.base.BasePresenter;
import com.zhihuitong.meeting.global.HuaWeiUserProvider;
import com.zhihuitong.meeting.global.MyApplication;
import com.zhihuitong.meeting.utils.ToastUtils;

/**
 * 作者： guoyuan
 * 时间 2020/2/24.
 * 文件描述：
 * 版本号：V 1.0
 **/
public class LoginPresenter extends BasePresenter<LoginContract.ILoginView> implements LoginContract.ILoginPresenter {
    public LoginPresenter(LoginContract.ILoginView view) {
        super(view);
    }

    /**
     * 登录鉴权
     *
     * @param account
     * @param pwd
     * @param userName
     */
    @Override
    public void login(final String account, final String pwd, String userName) {
        //本地保存用户名和棉棉
        MyApplication.setLocalAccount(account);
        MyApplication.setLocalPwd(pwd);
        MyApplication.setLocalUserName(userName);
        getView().loginSuc(account, pwd);
    }

    @Override
    public void releaseUser(String userName, String passWord) {
        HuaWeiUserProvider.releaseHuaWeiUser(userName, passWord, new HuaWeiUserProvider.onHuaWeiUserListener() {
            @Override
            public void onHuaWeiUserSuccess(String userId, String pwd) {
                ToastUtils.showToast("释放成功！");
            }

            @Override
            public void onHuaWeiUserFail(String msg) {
                ToastUtils.showToast(msg);
            }
        });
    }

    @Override
    public void getUser(String userName, final String passWord) {
        HuaWeiUserProvider.getUser(userName, passWord, new HuaWeiUserProvider.onHuaWeiUserListener() {
            @Override
            public void onHuaWeiUserSuccess(String userId, String pwd) {
                ToastUtils.showToast("申请成功！" + userId + "=" + pwd);
            }

            @Override
            public void onHuaWeiUserFail(String msg) {
                ToastUtils.showToast(msg);
            }
        });
    }


}
